package com.lab.es.demo.message;

import com.lab.es.demo.dto.UpdateItemDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SendMessage {
    @Value("${rocketmq.topic.testDelayTopic}")
    private String testDelayTopic;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public void sendItem(UpdateItemDTO updateItemDTO) {
        log.info(StringUtils.center("testDelayTopic", 52, "="));

        SendResult sendResult = rocketMQTemplate.syncSend(testDelayTopic, MessageBuilder.withPayload(updateItemDTO).build(),3000,3);
        log.info("syncSend to topic {} sendResult={} %n", testDelayTopic, sendResult);
    }
}
